<?php
include("../inc/Function.php");
if ((($_FILES["file"]["type"] == "image/gif")|| ($_FILES["file"]["type"] == "image/jpeg")|| ($_FILES["file"]["type"] == "image/png"))&& ($_FILES["file"]["size"] < 2000000)){
	if ($_FILES["file"]["error"] > 0){
	  echo "Error: " . $_FILES["file"]["error"] . "<br />";
	}
	else{
	  //echo "Upload: " . $_FILES["file"]["name"] . "<br />";
	  //echo "Type: " . $_FILES["file"]["type"] . "<br />";
	  //echo "Size: " . intval($_FILES["file"]["size"] / 1024) . " Kb<br />";
	  
	  //echo "Stored in: " . $_FILES["file"]["tmp_name"];
	  $year = date('Y',time());
	  $yue = date('m',time());
	  $ri = date('d',time());
	  $riqi = date('md',time());
	  if($_FILES["file"]["type"]=="image/jpeg") $filetype = "jpg";
	  if($_FILES["file"]["type"]=="image/gif") $filetype = "gif";
	  if($_FILES["file"]["type"]=="image/png") $filetype = "png";
	  $rq = $riqi.time().rand(1000,9999);
	  if(!file_exists("./../upload/$year$yue$ri")){
		  $qx = umask(0);
		  mkdir("./../upload/$year$yue$ri",0777,true);
		  umask($qx);
		  $info = move_uploaded_file($_FILES["file"]["tmp_name"],"./../upload/$year$yue$ri/" .$rq.".".$filetype);
		  $imgpath = "/upload/$year$yue$ri/" .$rq.".".$filetype;
		  //echo "文件路径: " . "/upload/$year$yue$ri/" .time().".".$filetype;
		}
		else{
		  $info = move_uploaded_file($_FILES["file"]["tmp_name"],"./../upload/$year$yue$ri/" .$rq.".".$filetype);
		  $imgpath = "/upload/$year$yue$ri/" .$rq.".".$filetype;
		  //echo "文件路径: " . "/upload/$year$yue$ri/" .time().".".$filetype;			 
		}
	}
}

$response = array();    
if($info){    
	$response['isSuccess'] = true;    
	$response['f'] = $imgpath;
}else{    
	$response['isSuccess'] = false;    
}
echo json_encode($response);  

?>